@extends('layouts.admin')
@section('content')
    <div id="content-header">
        <h1>用户管理</h1>
        <div class="btn-group">
            <a class="btn btn-large tip-bottom" title="Manage Files"><i class="icon-file"></i></a>
            <a class="btn btn-large tip-bottom" title="Manage Users"><i class="icon-user"></i></a>
            <a class="btn btn-large tip-bottom" title="Manage Comments"><i class="icon-comment"></i><span class="label label-important">5</span></a>
            <a class="btn btn-large tip-bottom" title="Manage Orders"><i class="icon-shopping-cart"></i></a>
        </div>
    </div>
    <div id="breadcrumb">
        <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>用户列表</a>
        <a href="#" class="current">用户添加</a>
    </div>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title">
								<span class="icon">
									<i class="icon-th"></i>
								</span>
                        <span class="label label-info" style="height:25px;line-height:20px;magin-left:0px;margin-top:5px">相册添加</span>
                    </div>
                    <div class="widget-content">

                        <div class="container-fluid">
                            <div class="row-fluid">
                                <div class="span12">
                                    <div class="widget-box">
                                        <div class="widget-title">
								<span class="icon">
									<i class="icon-align-justify"></i>
								</span>
                                            <h5>轮播图</h5>
                                        </div>
                                        <div id="err" style="color:red"></div>
                                <div class="widget-content">
								<table class="table table-bordered table-striped with-check">
									<thead>
										<tr>
											<th>排序</th>
											<th>ID</th>
											<th>相册名称</th>
                                            <th>相册图片</th>
											<th>相册描述</th>
											<th>增添时间</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody>
									@foreach($album as $u)
										<tr>
											<td style="text-align:center;vertical-align:middle" ><input type="text" name="ord[]" value="{{$u->order}}" style="width:40px;text-align:center;line-height:50px;margin-bottom:0px" onchange="changeOrder(this,{{$u->id}})"></td>
											<td style="text-align:center;vertical-align:middle" class="idds">{{$u->id}}</td>
											<td style="text-align:center;vertical-align:middle" class="names">{{$u->name}}</td>
											<td style="text-align:center;vertical-align:middle" id="big"><img src="{{$u->path}}" alt="" width="100px"></td>
											<td style="text-align:center;vertical-align:middle">{{$u->describe}}</td>
											<td style="text-align:center;vertical-align:middle">{{date("Y-m-d H:m:s",$u->ctime)}}</td>
											<td style="text-align:center;vertical-align:middle"><button type="button" class="btn btn-success"><a href="{{url('admin/album/'.$u->id. '/edit')}}" style="color:white">修改</a></button> |
                                                <button type="button" class="btn btn-success"><a href="javascript:" onclick="delArt({{$u->id}})" style="color:white">删除</a></button>
                                                <button type="button" class="btn btn-danger" id="btn">添加照片</button>
                                            </td>
										</tr>
                                        <tr>
                                            <td colspan="7" id="path"></td>
                                        </tr>
										@endforeach
									</tbody>
								</table>
							</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="row-fluid">
                <div id="footer" class="span12">
                    2012 &copy; Unicorn Admin. Brought to you by <a href="https://wrapbootstrap.com/user/diablo9983">diablo9983</a>
                </div>
            </div>
        </div>
        <form action="javascript:void(0)" method="post" class="form-horizontal" id="form1" enctype="multipart/form-data" style="z-index:-1;position:absolute;left:600px;top:100px;background:rgb(198,167,233)"/>

        <table style="margin:0 auto">
            <input type="hidden" name="_token" value="{{csrf_token()}}"/>
            <tbody>
            <tr>
                <th>相册名称：</th>
                <td>
                    <input type="text" class="lg" id='xc1' name="album_name" style="margin: 10px;width:200px;height:30px" value="">
                </td>
            </tr>
            <tr>
                <th>相片名称：</th>
                <td>
                    <input type="text" class="lg" name="name" style="margin: 10px;width:200px;height:30px" value="">
                </td>
            </tr>
            <tr>
                <th>缩略图：</th>
                <td>
                    <input id="file_upload" name="path[]" type="file" multiple="true">
            </tr>
            <tr>
                <th>描述：</th>
                <td>
                    <textarea name="describe"></textarea>
                </td>
            </tr>
            <tr>
                <th>排序：</th>
                <td>
                    <input type="text" name="order" value="" id="order" style="margin: 10px;width:200px;height:30px"/>
                </td>
            </tr>
            <tr>
                <td>
                    <button type="submit" id="btntn" class="btn btn-primary" style="width:60px">提交</button>
                    <button type="submit" id="btntn" class="btn btn-success" style="width:60px" onclick="window.location.reload()">返回</button>
                </td>
            </tr>
            </tbody>
        </table>
        </form>
	<script type="text/javascript">
            $('#form1').hide();
            $("#path").slideUp();
                function changeOrder(obj,id) {
                    var order = $(obj).val();
                    $.post("{{url('admin/album/changeOrder')}}", {
                        '_token': '{{csrf_token()}}',
                        'id': id,
                        'order': order
                    }, function (data) {
                        console.log(data);
                        if (data.status == 0) {
                            layer.alert(data.msg, {icon: 6});
                        } else {
                            layer.msg(data.msg, {icon: 5});
                        }
                    });
                }
                // 删除友情导航
                function delArt(id){
                    layer.confirm('您确定要删除？', {
                        btn: ['确定','取消'] //按钮
                    }, function(){
                        $.post("{{url('admin/album')}}/"+id,{'_method':'delete','_token':'{{csrf_token()}}'},function(data){
                            console.log(data);
                            if(data.status==0){
                                location.href=location.href;
                                layer.msg(data.msg,{icon:6});
                            }else{
                                layer.msg(data.msg,{icon:5});
                            }
                        });
                    }, function(){

                    });
                }
                var btn = document.getElementsByClassName('btn btn-danger');
//                console.log(btn);
                 var a=document.getElementsByClassName('names');
                 var id =document.getElementById('xc');
                 var album =document.getElementById('xc1');
//                 console.log(a);
//                 console.log(btn.length);
                for(var i=0;i<btn.length;i++) {
                // console.log(i);
                (function (i) {
                        btn[i].onclick = function(){
                             ass = a[i].innerHTML;
                            album.value = ass;
                            $('#form1').toggle();
                            $('#form1').css('z-index',10);
                        }
                     })(i);
                    }
                var img = document.getElementsByTagName('img');
                var a=document.getElementsByClassName('names');
                var big=document.getElementById('big');
//                img.parents('tr').next('tr').next('tr').show();
                for(var i=0;i<img.length;i++) {
                    // console.log(i);
                    (function (i) {
                        img[i].onclick = function (event) {
                           var ass = a[i].innerHTML;
                            $.ajax({
                                type:'post',
                                dataType:'json',
                                data:{'date':ass,'_token':'{{csrf_token()}}'},
                                url:'{{url('admin/album/child')}}',
                                success:function (data) {
//                                    console.log(1111);
//                                    console.log(data);
//                                    if(data.status==0){
//                                        location.href=location.href;
//                                        layer.msg(data.msg,{icon:6});
//                                    }else{
//                                        layer.msg(data.msg,{icon:5});
//                                    }
                                },
                                error:function(data){
//                                    console.log(data);
                                   imgs=$('#path').html(data.responseText);
                                    $("#path").slideToggle('slow');
                                    $("#test a:first-child")
                                    var ps=$('#path > div').length;
                                    console.log();
                                    for(var i=0;i<ps;i++) {
                                        (function (i) {
                                            $('#path > div').eq(i).click(function (event) {
                                                var imges = $('#path > div').eq(i).html();
                                                var imgz = imges.substr(10);
                                                 var imgs = imgz.substr(0,28);
                                                 console.log(ass);
                                                $.ajax({
                                                    type: 'post',
                                                    dataType: 'json',
//                                                    processData: false,
//                                                    contentType: false,
                                                    data:{'data':imgs,'ass':ass,'_token':'{{csrf_token()}}'},
                                                    url: '{{url('admin/album/repeact')}}',
                                                    success: function (data) {
                                                        if (data.status == 0) {
                                                           location.href = location.href;
                                                           layer.msg(data.msg, {icon: 6});
                                                        } else {
                                                           layer.msg(data.msg, {icon: 5});
                                                        }
                                                    },
                                                    error: function (data) {
                                                        console.log(data);
                                                    }

                                               });
                                            })
                                            })(i);
                                    }
//                                   console.log(imgs[0].firstChild.innerHTML);
//                                   big.innerHTML=imgs[0].firstChild.innerHTML;

                                }

                            });
//                            console.log($(this).parents('tr').children('.idds').html());
//                            console.log($(this));
//                            console.log($("#xc").val($(this).parents('tr').children('.idds').html()));
//                            console.log($("#xc").val());
                        }
                    })(i);
                }
                $('#btntn').click(function(){
                    var myform = document.getElementById('form1');
                    var date = new FormData(myform);
//                    console.log(date);
                    $.ajax({
                        type:'post',
                        dataType:'json',
                        processData:false,
                        contentType:false,
                        data:date,
                        url:'{{url('admin/album/chan')}}',
                        success:function (data) {
//                            console.log(data);
                            if(data.status==0){
                                location.href=location.href;
                                layer.msg(data.msg,{icon:6});
                            }else{
                                layer.msg(data.msg,{icon:5});
                            }
                        },
                        error:function(data){
                            console.log(data);
                        }

                    });

                });

                //                $('.showquestion').click(function(){
//                    $('.asd').hide();
//                    $(this).parents('tr').next('tr').next('tr').show();
//                    // $(this).parents('tr').next('.question1').show();
//                });

    </script>
@endsection

